package com.example.library_demo.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.library_demo.entity.Shelf;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.library_demo.vo.shelf.ShelfVO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Eric
 * @since 2024-11-27
 */
public interface ShelfMapper extends BaseMapper<Shelf> {

    @Select("SELECT s.*, m.currentBookCount FROM l_shelf s " +
            "left join (" +
            "select shelf_id,count(book_id) currentBookCount " +
            "from l_book group by shelf_id) m " +
            "on s.shelf_id = m.shelf_id")
    IPage<ShelfVO> selectShelves(Page page);

}
